package com.ztz.mynewdemo.activity;

import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.ztz.mynewdemo.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ZhanKuActivity extends BaseActivity {
    public final static String CONTENTURL = "url";
    String url;
    @BindView(R.id.zhanku_webView)
    WebView webView;
    @BindView(R.id.content_progress)
    ProgressBar contentProgress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_zhan_ku);
        ButterKnife.bind(this);
        setToolbar("站酷");
        url = getIntent().getStringExtra(CONTENTURL);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setAllowContentAccess(true);
        webSettings.setAppCacheEnabled(false);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl(url);
        webView.setWebChromeClient(new WebChromeClient()
        {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if(newProgress==100)
                {
                    contentProgress.setVisibility(View.GONE);
                }
                else {
                    contentProgress.setVisibility(View.VISIBLE);
                    contentProgress.setProgress(newProgress);
                }
                super.onProgressChanged(view, newProgress);
            }
        });
    }
}
